package com.industry.system.support;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.industry.system.satoken.StpContextHelper;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Author nbZhuozh
 * @Date 2025-02-17  11:07
 **/
@Component
public class IdooMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        String userId = StpContextHelper.getUserInfo().getId();
        if(null != userId) {
            this.strictInsertFill(metaObject,"createUser",String.class,userId);
        }
        this.strictInsertFill(metaObject,"createTime", LocalDateTime.class , LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        String userId = StpContextHelper.getUserInfo().getId();
        if(null != userId) {
            this.strictInsertFill(metaObject,"updateUser",String.class,userId);
        }
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class , LocalDateTime.now());
    }
}
